home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7460 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Constructor classes
  5. Date: 23 Feb 1996 11:38:10 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4gk8v2$2lv@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe8.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Feb 22, 1996 17:17:16 in article <Constructor classes>,
  15. 'scalish@execpc.com (Sherri Scalish)' wrote: 
  16.  
  17.  
  18. >Hope someone can help me, I'm getting very frustrated.  I have a container
  19.  
  20. >class in which I have an array of classes: 
  21. >    class OtherClass{ 
  22. >    private: 
  23. >        char m_itema[30]; 
  24. >        char m_itemb[30]; 
  25. >        ... 
  26. >    }: 
  27. >    class ContainerClass{ 
  28. >    public: 
  29. >        OtherClass Items[9]; 
  30. >    ... 
  31. >    }; 
  32.  
  33. >How do I access the array's data members?  
  34.  
  35. You can't -- not the way you've declared OtherClass; i.e., 
  36. the data members are private. 
  37.  
  38. > I have tried: 
  39. >    m_itema[0], ContainerClass->m_itema[0], ContainerClass.m_itema[0],  
  40. >OtherClass->m_itema[0]. OtherClass.m_itema[0], etc. etc. 
  41. >I have been working on this for days and am getting truly frustated.  I  
  42. >would greatly appreciate an E-Mail to solve this mystery.   
  43. >scalsh@execpc.com.  Thanks in advance!!!!     
  44.  
  45. If you declare the data members in OtherClass as public, 
  46. then you can access them as follows: 
  47.  
  48. ContainerClass x, *px; 
  49.   x.Items[0].m_itema[20]; 
  50.   px->Items[8].m_itemb[30]; 
  51.  
  52. BTW, I would under most circumstances keep the data members 
  53. private and provide appropriate accessor functions instead.  But 
  54. that's strictly a design issue.  Just something to think about. 
  55.  
  56. -- 
  57. Pete Grant 
  58. Kalevi, Inc. 
  59. Software Engineering & development
  60.